package com.project.service;

import com.project.dao.CompAnswerMapper;
import com.project.entity.CompAnswer;
import com.project.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(rollbackFor = Exception.class)
@Service
public class CompAnswerServiceImpl extends BaseService implements CompAnswerService {

    @Autowired
    CompAnswerMapper compAnswerMapper;

    @Override
    public void add(CompAnswer compAnswer) {
        compAnswerMapper.insertSelective(compAnswer);
    }

    @Override
    public String[] findByCompidOrderByIndex(Integer compid) {
        List<CompAnswer> compAnswerList = compAnswerMapper.selectByCompidOrderByIndex(compid);
        String[] answerAray = new String[compAnswerList.size()];
        for(CompAnswer compAnswer : compAnswerList){
            answerAray[compAnswer.getIndex()-1] = compAnswer.getAnswer();
        }
        return answerAray;
    }

    @Override
    public int modify(CompAnswer compAnswer)
    {
        return compAnswerMapper.updateByPrimaryKeySelective(compAnswer);
    }
}
